<?php
include ("includes/header.php");
include ("includes/connection.php");
include ("includes/login.php");
include ("includes/iniciaSessio.php");
?>

<body>
	<?php
$alias=$_SESSION["username"];
$sql="SELECT * FROM usuari where alias ='$alias'";
$res=mysql_query($sql);
if (!$res) {
$missatge = 'Consulta Invalida: ' . mysql_error() . "\n";
$missatge .= 'Consulta SQL: ' . $sql;
}
if ($row=mysql_fetch_array($res))



	?>
<body>
	<?php
	include ("includes/contentHeader.php");
	?>
	<!--contingut 1-->
	<section class="container">
		<!--fons gris-->
		<div class="hero-unit">
			<form name="registre" action="modificar_contrasenya.php"  class="form-horizontal" method="post">
				<div class="row show-grid">
					<fieldset class="span6 ">
						<legend>
							Modificar Contrasenya
						</legend>
						<label  for="pass">Contrasenya vella:</label>
						<input class="input-medium" name="pass" type="password" value=" <?php echo $row['contrasenya']?> "/>
						<label  for="pass2">Introdueix contrasenya nova:</label>
						<input class="input-medium" name="pass2" type="password" value="pass2"/>
						<label  for="pass3">Repeteix contrasenya nova:</label>
						<input class="input-medium" name="pass3" type="password" value="pass3"/>
						<button class="btn" name="modificar" type="submit" value="Modificar">
							Modificar
						</button>
			</form>
			<button class="btn" name="cancelar" type="button" value="Anar enrere" onmousedown="location.href = 'perfil_usuari.php'">
				Cancelar
			</button>
			</fieldset> <?php
			if (isset($_POST['modificar'])) {
			mysql_select_db("sintesi", $conexion);

			if (isset($_SESSION["sessionID"])) {
				$pass = $_POST['pass2'];
				$alias = $_SESSION["username"];
				$consulta = "UPDATE usuari SET contrasenya = '$pass' WHERE alias = '$alias'";

				$result = (mysql_query($consulta, $conexion));

				if ($result) {
					echo "	<script>
alert('Contrasenya canviada');
</script>";

				}
				else
				{
									echo "	<script>
alert('Error al canviar contrasenya');
</script>";	
				}

			}
			}
			?>

			<div class="span6">
				<img src="images/registro2.png" width=300 height=300 border=2 alt="Comparteix coche">
				<br />
			</div>
		</div>
		</div> <!-- fi fons gris-->
	</section>
	<!-- fi contingut 1-->
	<!--contingut 2-->
	<section class="container">
		<div class="hero-unit"></div>
	</section>
	<!-- fi contingut 2-->
	<hr>
	<?php
	include ("includes/footer.php");
	?>
